package com.cfgj.web;

import com.cfgj.entity.Fabu;
import com.cfgj.entity.GongGao;
import com.cfgj.service.GonggaoService;
import com.cfgj.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/gg")
public class GgController {
    @Autowired
    private GonggaoService gonggaoService;

    @RequestMapping("/gg-list")//路径
    public String admin(Model model){
        List<GongGao> findgonggao=gonggaoService.findgonggao();
        model.addAttribute("findgonggao",findgonggao);
        return "admin/gg-list";
    }

       @RequestMapping("/gg1")
    public String text(){return "admin/text";}

    @ResponseBody
    @RequestMapping("/fabu")
    public String fabugg(HttpServletRequest request) throws ParseException {
        Fabu fabu=new Fabu();
       String name= request.getParameter("name");
       String time=request.getParameter("time");
       String content=request.getParameter("content");
       String faburen = request.getParameter("faburen");
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd");
                Date date=sdf.parse(time);
                fabu.setTime(date);
                fabu.setName(name);
                fabu.setContent(content);
                fabu.setFaburen(faburen);
                fabu.setCreatetime(date);

        gonggaoService.savegonggao(fabu);
        return "公告上传成功，请关闭并刷新页面！";
    }
}

